﻿using Microsoft.VisualStudio.TestTools.UnitTesting;

using DatabaseGroup.SSIS.SourceAdapters;

namespace DatabaseGroup.UnitTests.SSIS.SourceAdapters
{
    [TestClass()]
    public class MessageStringsTest
    {
        private TestContext _testContextInstance;

        public TestContext TestContext
        {
            get
            {
                return _testContextInstance;
            }
            set
            {
                _testContextInstance = value;
            }
        }
        
        [TestMethod()]
        public void UnsupportedDataType_DummyValues_ReturnProperlyFormattedString()
        {
            VeryfyMessageString(MessageStrings.UnsupportedDataType("DT_BYTES"), new string [] {"DT_BYTES"});
        }

        [TestMethod()]
        public void RowOveflow_DummyValues_ReturnProperlyFormattedString()
        {
            VeryfyMessageString(MessageStrings.RowOverflow(17, 33, 12), new string[] { "17", "33", "12" });
        }

        [TestMethod()]
        public void PropertyStringTooLong_DummyValues_ReturnProperlyFormattedString()
        {
            VeryfyMessageString(MessageStrings.PropertyStringTooLong("propertyName", "propertyValue"), new string[] { "propertyName", "propertyValue" });
        }

        [TestMethod()]
        public void ParsingBufferOverflow_DummyValues_ReturnProperlyFormattedString()
        {
            VeryfyMessageString(MessageStrings.ParsingBufferOverflow(17, 33, 64000), new string[] { "17", "33", "64000" });
        }

        [TestMethod()]
        public void MaximumColumnNumberOverflow_DummyValues_ReturnProperlyFormattedString()
        {
            VeryfyMessageString(MessageStrings.MaximumColumnNumberOverflow(17, 2000), new string[] { "17", "2000" });
        }

        [TestMethod()]
        public void InvalidPropertyValue_DummyValues_ReturnProperlyFormattedString()
        {
            VeryfyMessageString(MessageStrings.InvalidPropertyValue("propertyName", "propertyValue"), new string[] { "propertyName", "propertyValue" });
        }

        [TestMethod()]
        public void InvalidPropertyDataType_DummyValues_ReturnProperlyFormattedString()
        {
            VeryfyMessageString(MessageStrings.InvalidPropertyDataType("propertyName", "propertyValue"), new string[] { "propertyName", "propertyValue" });
        }

        [TestMethod()]
        public void InvalidConnectionReference_DummyValues_ReturnProperlyFormattedString()
        {
            VeryfyMessageString(MessageStrings.InvalidConnectionReference("Connection"), new string[] { "Connection" });
        }

        [TestMethod()]
        public void FileDoesNotExist_DummyValues_ReturnProperlyFormattedString()
        {
            VeryfyMessageString(MessageStrings.FileDoesNotExist("c:\\temp\\file.txt"), new string[] { "c:\\temp\\file.txt" });
        }

        [TestMethod()]
        public void FailedToAssignColumnValue_DummyValues_ReturnProperlyFormattedString()
        {
            VeryfyMessageString(MessageStrings.FailedToAssignColumnValue(17, "some data", "column \"First column\" (343)"), new string[] { "17", "some data", "column \"First column\" (343)" });
        }

        [TestMethod()]
        public void DefaultColumnName_DummyValues_ReturnProperlyFormattedString()
        {
            VeryfyMessageString(MessageStrings.DefaultColumnName(77), new string[] { "77" });
        }

        [TestMethod()]
        public void CantFindProperty_DummyValues_ReturnProperlyFormattedString()
        {
            VeryfyMessageString(MessageStrings.CantFindProperty("propertyName"), new string[] { "propertyName" });
        }

        /// <summary>
        /// Asserts that the message string contains all the specified substrings
        /// </summary>
        /// <param name="messageString">The message string to test</param>
        /// <param name="substrings">The substrings to test for</param>
        private void VeryfyMessageString(string messageString, string[] substrings)
        {
            Assert.IsFalse(string.IsNullOrEmpty(messageString), "The message string is null/empty");

            foreach (string substring in substrings)
            {
                Assert.IsTrue(messageString.Contains(substring), "Message string does not contain the expected substrings");
            }
        }
    }
}
